package pcb.control.responders 
{
	import com.intel.core.Application;
	import com.intel.service.ServiceEvent;
	import com.intel.utils.Debugger;
	import flash.display.MovieClip;
	import flash.display.StageAlign;
	import flash.display.StageDisplayState;
	import flash.display.StageScaleMode;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import pcb.control.events.LoadDataEvent;
	
	/**
	 * ...
	 * @author Fintan Boyle
	 */
	public class Re_loadLessonSwf extends AbstractResponder 
	{
		
		public function Re_loadLessonSwf() 
		{
			Debugger.traceOut("Re_loadLessonSwf constructed");
		}
		
		override public function result(e:ServiceEvent):void 
		{
			Debugger.traceOut("Re_loadLessonSwf >>" +e.type + " - " + e.message);
			
			
			models.lessonStateModel.mainStage = e.data as MovieClip;
			
			if (models.playerSettings.scaleToFit) {
				Application.stage.align = StageAlign.TOP;
				Application.stage.scaleMode = StageScaleMode.SHOW_ALL;
				Application.stage.displayState = StageDisplayState.FULL_SCREEN;
			}
			
			var t:Timer = new Timer(1500,1);
			t.addEventListener(TimerEvent.TIMER_COMPLETE, t_onComplete);
			t.start();
			
			//important for garbage collection
			super.cleanup(e);
		}
		
		private function t_onComplete(e:TimerEvent):void 
		{
			var ev2:LoadDataEvent = new LoadDataEvent(LoadDataEvent.LOAD_LESSON_TEXT);
			ev2.data = models.lessonStateModel.lessonId;
			ev2.dispatch();
			e.target.stop();
			e.target.removeEventListener(TimerEvent.TIMER_COMPLETE, t_onComplete)
		}
		
	}
	
}